<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bg {
            background-color: blueviolet;
        }
    </style>
</head>

<body>
    <button>全选</button>
    <button>不选</button>
    <button>反选</button>
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <script>
        window.onload = function () {
            let btn = document.getElementsByTagName("button");
            btn[0].onclick = () => {
                let inp = document.getElementsByTagName("input");
                console.log(inp)
                for (let i = 0; i < inp.length; i++) {
                    inp[i].checked = true
                }
            }
            btn[1].onclick = () => {
                let inp = document.getElementsByTagName("input");
                console.log(inp)
                for (let i = 0; i < inp.length; i++) {
                    inp[i].checked = false
                }
            }
            btn[2].onclick = () => {
                let inp = document.getElementsByTagName("input");
                console.log(inp)
                for (let i = 0; i < inp.length; i++) {
                    if (inp[i].checked == true) {
                        inp[i].checked = false;
                        // console.log("1");
                    }
                    else {
                        inp[i].checked = true
                    }

                }
            }
        }
    </script>
</body>

</html>